package com.qzsoft.zhjd.asphalt.modules.asphaltreport.service.impl;

import java.util.List;
import java.util.Map;

import com.qzsoft.zhjd.asphalt.modules.asphaltmatch.entity.AsphaltMatchEntity;
import com.qzsoft.zhjd.asphalt.modules.asphaltmatch.service.AsphaltMatchService;
import com.qzsoft.zhjd.asphalt.modules.asphaltreport.mapper.AsphaltReportMatchMapper;
import com.qzsoft.zhjd.asphalt.modules.asphaltreport.service.AsphaltReportMatchService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import com.baomidou.mybatisplus.core.toolkit.ObjectUtils;
import com.qzsoft.zhjd.asphalt.modules.asphaltreport.dto.AsphaltOutputAnalysisDto;
import com.qzsoft.zhjd.asphalt.modules.asphaltreport.dto.AsphaltOutputCountDto;
import com.qzsoft.zhjd.asphalt.modules.asphaltreport.dto.AsphaltProduceDataDto;
import com.qzsoft.zhjd.asphalt.modules.asphaltreport.dto.AsphaltRatioDistDto;
import com.qzsoft.zhjd.asphalt.modules.asphaltreport.dto.AsphaltReportMatchDto;
import com.qzsoft.zhjd.asphalt.modules.asphaltreport.dto.AsphaltTempDistDto;
import com.qzsoft.zhjd.common.enums.BizCode;
import com.qzsoft.zhjd.common.utils.RenExceptionUtils;

/**
 * @ClassName AsphaltReportMatchServiceImpl
 * @Description 生产配比数据报表业务接口实现
 * @author linhuawei
 * @since 2022-02-08
 */
@Service
public class AsphaltReportMatchServiceImpl implements AsphaltReportMatchService {

    @Autowired
    private AsphaltMatchService asphaltMatchService;

    @Autowired
    private AsphaltReportMatchMapper asphaltReportMatchMapper;

    @Override
    public AsphaltReportMatchDto info(Map<String, Object> params) {
        // 获取拌合楼编号、配方编号
        String stationCode = null == params.get("stationCode") ? null : params.get("stationCode").toString();
        String matchCode = null == params.get("matchCode") ? null : params.get("matchCode").toString();
        if (ObjectUtils.isEmpty(stationCode) || ObjectUtils.isEmpty(matchCode)) {
            RenExceptionUtils.throwEx(BizCode.PARAMS_ERROR, "拌合楼、配方不可为空");
        }

        // 获取配方信息
        AsphaltMatchEntity match = asphaltMatchService.getByCode(matchCode);
//        if(null == match) {
//            RenExceptionUtils.throwEx(BizCode.PARAMS_ERROR, "生产配比不存在");
//        }
        if (null == match) {
            match = new AsphaltMatchEntity();
        }

        // 获取产量信息
        List<AsphaltOutputCountDto> outputCountList = asphaltReportMatchMapper.getOutputCountList(params);

        // 获取产量分析
        AsphaltOutputAnalysisDto outputAnalysis = asphaltReportMatchMapper.getOutputAnalysis(params);
        if (null != outputAnalysis) {
            outputAnalysis.count();
        }

        // 获取生产数据
        List<AsphaltProduceDataDto> produceDataList = asphaltReportMatchMapper.getProduceDataList(params);

        // 获取温度分布图
        List<AsphaltTempDistDto> tempDistList = asphaltReportMatchMapper.getTempDistList(params);

        // 获取油石比分布图
        List<AsphaltRatioDistDto> ratioDistList = asphaltReportMatchMapper.getRatioDistList(params);

        // 返回结果
        AsphaltReportMatchDto dto = new AsphaltReportMatchDto();
        dto.setMatch(match);
        dto.setOutputCountList(outputCountList);
        dto.setOutputAnalysis(outputAnalysis);
        dto.setProduceDataList(produceDataList);
        dto.setRatioDistList(ratioDistList);
        dto.setTempDistList(tempDistList);
        return dto;
    }

}
